/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __PQ_PlayerSession_H__
#define __PQ_PlayerSession_H__

#include "PQNet.h"
#include "Player.h"
#include "TCPSocket.h"
#include "NetInputStream.h"
#include "NetOutputStream.h"

namespace PQServiceLogin
{
	/*Security level also refer to user account type
	*/
	enum SecurityLevel
	{
		Security_Level_Player=0,
		Security_Level_Moderator=1,
		Security_Level_GameMaster=2,
		Security_Level_Administrator=3,
		Security_Level_Console=4
	};

	/* Player session in the world,each player have one.
	*/
	class PlayerSession
	{
	public:
		PlayerSession(SOCKET socket);
        ~PlayerSession();

		void update(float deltaT);

		//init player info after connection OK
		void init();

		void setIsConnected(bool connected);


		void setPlayerState(PlayerState state);
		PlayerState getPlayerState();

		void cleanUp();

		bool processInput();
		bool processOutput();
		bool processCommand();

		SOCKET getSocketHandle();
		PQNet::TCPSocket* getSocket();
		
		inline int getSessionId() const { return _sessionId; }
		inline Player* getPlayer() const { return _player; }
		inline SecurityLevel getSecurityLevel() const { return _securityLevel; }

		//void sendPacket(const Packet* packet);
		//void queuePacket(Packet* packet);
		//void executeOpcode(const OpcodeHandler& handler, Packet* packet);
	protected:
		PQNet::TCPSocket *_socket;
		//input output stream
		PQNet::NetInputStream* _inputStream ;
		PQNet::NetOutputStream* _outputStream ;

	protected:
		Player* _player;
		PlayerState _playerState;
		SecurityLevel _securityLevel;
	protected:
		static int totalCount;
		int _sessionId;
		bool _isConnected;

		int _kickTime;//
		int _lastSendTime;
		int _connectTime;
		int _time;//current time

	public:
		// opcodes handlers
        //void handle_NULL(Packet& recvPacket);          // not used
       
	};

}

#endif
